package com.wuxiaoqin.admin.controller;


import com.wuxiaoqin.admin.entity.AddCommodity;
import com.wuxiaoqin.admin.entity.goodParam.GoodsstockUpdate;
import com.wuxiaoqin.admin.service.IGoodsstockService;
import com.wuxiaoqin.uitls.respObj.RespBean;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-11-08
 */
@RestController
@RequestMapping("/goodsstock")
public class GoodsstockController {

    @Autowired
    private IGoodsstockService goodsstockService;

    @ApiOperation("查询商品库存")
    @GetMapping("/getGoodsStock/{goodsId}")
    public RespBean getGoodsStock(@PathVariable("goodsId") Integer goodsId)  {

        return goodsstockService.getGoodsStock(goodsId);
    }

    @ApiOperation("更改商品库存")
    @PostMapping("/updateGoodsStock")
    public RespBean updateGoodsStock( GoodsstockUpdate goodsstockUpdate)  {

        return goodsstockService.updateGoodsStock(goodsstockUpdate);
    }
    @ApiOperation("增加单个尺码库存,尺码小写如m、l、xxl,addOrSubtract为true增加，false减少")
    @PostMapping("/addOrSubtractStock")
    public RespBean addOrSubtractStock(@RequestParam("goodsId") Integer goodsId,
                                       @RequestParam(value = "addOrSubtract",defaultValue = "true")  Boolean addOrSubtract,
                                       @RequestParam("size") String size,
                                       @RequestParam("sum") Integer sum)  {

        return goodsstockService.addOrSubtractStock(goodsId,addOrSubtract,size,sum);
    }
}
